package com.carkeeper.bill.controller;

import com.carkeeper.bill.pojo.Bill;
import com.carkeeper.bill.service.BillService;
import com.carkeeper.common.utils.PageResult;
import com.carkeeper.common.utils.Result;
import com.carkeeper.common.utils.StatusCode;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zhouliang
 * @version 1.0
 * @date 2020/11/27 9:35
 */
@RestController
@RequestMapping("/bill")
@Api(tags = "服务商账单接口api")
@CrossOrigin
public class BilController {

    @Autowired
    private BillService billService;

    /**
     * 条件+分页查询
     * @param searchMap
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/search/{page}/{size}" )
    @ApiOperation("账单条件+分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code",value = "账单编号"),
            @ApiImplicitParam(name = "storeName",value = "商家名称"),
            @ApiImplicitParam(name = "payState",value = "支付状态"),
            @ApiImplicitParam(name = "createTime",value = "账单日期"),
    })
    public Result findPage(@RequestParam Map searchMap, @PathVariable int page, @PathVariable  int size){
        Page<Bill> pageList = billService.findPage(searchMap, page, size);

        PageResult pageResult=new PageResult(pageList.getTotal(),pageList.getResult());

        return new Result(true, StatusCode.OK,"查询成功",pageResult);
    }

    /**
     * 根据账单id查询账单详情
     * @param id
     * @return
     */
    @GetMapping("/findBillDetails/{id}" )
    @ApiOperation("账单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键")
    })
    public Result findBillDetails(@PathVariable("id")  Integer id){
        Map<String, Object> details = billService.findBillDetails(id);
        return new Result(true, StatusCode.OK,"查询成功",details);
    }

   /* @GetMapping("/find/{page}/{size}")
    public Result findBill(@PathVariable("page") int page,@PathVariable("size") int size) {

        Page<Map<String, Object>> bill = billService.findBill(page, size);
        PageResult pageResult = new PageResult(bill.getTotal(),bill.getResult());

        return new Result(true, StatusCode.OK,"查询成功",pageResult);
    }*/

}
